package org.alanlau.hystrix.simple;

import com.netflix.hystrix.HystrixCommand;
import com.netflix.hystrix.HystrixCommandGroupKey;
import com.netflix.hystrix.HystrixCommandProperties;

import java.util.concurrent.ExecutionException;

/**
 * 信号量策略配置
 *
 * @author liukun
 * @version 1.0
 * @date 2020/9/14 20:19
 */
public class MyHystrixCommand3 extends HystrixCommand<String> {
    private final String name;

    public MyHystrixCommand3(String name) {
        super(HystrixCommand.Setter
                .withGroupKey(HystrixCommandGroupKey.Factory.asKey("MyGroup"))
                .andCommandPropertiesDefaults(HystrixCommandProperties.Setter()
                        .withExecutionIsolationStrategy(HystrixCommandProperties.ExecutionIsolationStrategy.SEMAPHORE)));
        this.name = name;
    }

    @Override
    protected String run() throws Exception {
        return this.name + ":" + Thread.currentThread().getName();
    }


    public static void main(String[] args) throws ExecutionException, InterruptedException {
        String result = new MyHystrixCommand3("alan").execute();
        System.out.println(result);
    }
}
